package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import domain.PageBean;
import domain.User;
import service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public User login(String username, String password) {
        User user = userDao.select(username,password);
        return user;
    }

    @Override
    public PageBean<User> findStudentsByPage(int pageNum, int pageSize, String where, List<Object> params) {

            long totalSize = userDao.selectCount(where, params); // 查询总数据量
            List<User> data = userDao.selectByPage(pageNum, pageSize, where, params);
            // 构建PageBean实例
            PageBean<User> pageBean = new PageBean<>(pageSize, pageNum, totalSize, data);
            return pageBean;
        }

    @Override
    public List<User> findAll() {
        return userDao.selectAll();
    }

    @Override
    public void remove(int uid) {
        userDao.deletestu(uid);
    }

    @Override
    public void addStudent(User user) {
        userDao.insert(user);
    }

    @Override
    public void updateStudent(User user) {
        userDao.update(user);
    }
}

